<?php
namespace app\admin\event\subscribes\user;

use app\admin\event\listeners\user\UserLastLogin;
use app\admin\event\listeners\user\UserTokenDelete;
use app\admin\event\listeners\user\UserTokenRefresh;
use app\admin\logic\system\Log;
use think\Event;

class Account
{
    public function subscribe(Event $event)
    {

        /** UserLogin 登录成功 */
        $event->listen('UserLogin', UserLastLogin::class);
        $event->listen('UserLogin', UserTokenRefresh::class);

        /** 新建 */
        $event->listen('UserCreated', function ($user) {
            Log::write('管理员【' . $user->user_name . '】', 'admin_user', 'create');
        });
        /** 更新 */
        $event->listen('UserUpdated', function ($user) {
            Log::write('管理员【' . $user->user_name . '】的信息', 'admin_user', 'update');
        });
        /** 删除 */
        $event->listen('UserDeleted', UserTokenDelete::class); // 删除token
        $event->listen('UserDeleted', function ($user) {
            Log::write('管理员【' . $user->user_name . '】', 'admin_user', 'delete');
        });

    }
}
